const { JSONCookie } = require('cookie-parser');
var express = require('express');
var router = express.Router();
const db = require('../db/connect');
/* GET home page. */
router.get('/', function(req, res, next) {
  res.setHeader('Content-Type', 'text/html; charset=utf-8')
  res.render('index', { title: 'Express' });
});

//---登陆
router.get('/login/login', function(req, res, next) {
  db.query('SELECT * from user_list where tel=? and pwd =?', [req.query.tel,req.query.pwd], 
  function(result, fields) {
    console.log(req.query,"0000");
    if(result.length){
       res.cookie('name',req.query.tel, { maxAge: 9000});
       res.send( { msg:'登陆成功', code:1})
    }else{
        res.send( {  msg:'登陆失败',  code:0 })
    }
  })
});
router.get('/my',function(req, res, next){
  var cookies = req.headers.cookie;  
   res.render('my.ejs',{
    'cookies':cookies
   })
})
router.post('/upload/',function(req,res,next){
   console.log(req.query,"0");
})


module.exports = router;
